﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WXYW.BLL;
using WXYW.DAL;

namespace WXYW
{
    public partial class ApplicationOverdueDetail : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.QueryString[Constants.QUERYSTR_APPLICATION_ID] != null)
                {                   
                    FillApplicationProductGridView();
                }
            }
        }

        private void FillApplicationProductGridView()
        {
            ApplicationService serivce = new ApplicationService();
            ApplicationForm applicationForm = serivce.GetApplicationFormDetailByID(long.Parse(Request.QueryString[Constants.QUERYSTR_APPLICATION_ID]));
            if (!applicationForm.UserReference.IsLoaded)
            {
                applicationForm.UserReference.Load();
            }

            // bind user information
            applyCompanyNameTxtBox.Text = applicationForm.User.CompanyName;
            mailAddressTxtBox.Text = applicationForm.User.UserAddress;
            applierEmailTxtBox.Text = applicationForm.User.UserEmail;
            applierFaxTxtBox.Text = applicationForm.User.UserFax;
            //rmaLabel.Text = applicationForm.ApplicationCode;
            runningNumberLabel.Text = applicationForm.ApplicationCode;
            //receiveLabel.Text = applicationForm.ReceiveDateTime.HasValue ? applicationForm.ReceiveDateTime.Value.ToString("yyyy-MM-dd") : "0000-00-00";
            //applierMobilePhoneTxtBox.Text = ContextService.CurrentAccount.UserMobilePhone;
            applierNameTxtBox.Text = applicationForm.User.UserName;
            applierPhoneTxtBox.Text = applicationForm.User.UserPhone;
            statusLabel.Text = applicationForm.Status;

            // bind product
            ProductGridView.DataSource = applicationForm.ApplicationProduct;
            ProductGridView.DataBind();
        }      
    }
}
